package com.longrise.android.byjk.plugins.publicWeb;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.longrise.android.byjk.R;
import com.longrise.android.byjk.model.UserInfor;
import com.longrise.android.byjk.plugins.aboutme.personalInfo.OpenLoginActivity;
import com.longrise.android.byjk.plugins.aboutme.personalInfo.PersonalExhibitionActivity;
import com.longrise.android.byjk.plugins.aboutme.personalInfo.PersonalInfoActivity;
import com.longrise.android.byjk.plugins.aboutme.personalInfo.PersonalPresenter;
import com.longrise.android.byjk.plugins.aboutme.personalInfo.change.BundlePhoneActivity;
import com.longrise.android.byjk.plugins.aboutme.personalInfo.change.ChangeInfoActivity;
import com.longrise.android.byjk.plugins.aboutme.personalInfo.product_show.AddProductShowActivity;
import com.longrise.android.byjk.plugins.tabfirst.CustomerModuleJumpHelper;
import com.longrise.android.byjk.plugins.productfeerate.UploadProductfeerateActivity;
import com.longrise.android.byjk.plugins.vip.dailysign.DailySignActivity;
import com.longrise.android.byjk.utils.DialogUtil;
import com.longrise.bymodule.utils.BYContants;

/**
 * Created by callxkj on 2017/3/28.
 * 获取相应web的url地址,并跳转到web页面
 * <p>
 * 也可以从web页面跳转到其他页面
 */

public class PublicWebJumpUtil {
    private static final String TAG = "PublicWebJumpUtil";

    /**
     * 从这个公共web页面跳转到其他页面
     */
    public static void jumpToActivity(Activity activity, String title, Bundle bundle) {
        if (bundle == null) {
            bundle = new Bundle();
        }
        switch (title) {
            case PublicWebPresenter.MRQD: //每日签到
                jump(activity, DailySignActivity.class, bundle);
                break;
            case PublicWebPresenter.ZYRZ: //执业认证 app现在不能更改不做处理了
                break;
            case PublicWebPresenter.SFRZ: //身份认证 需要姓名和身份证都完善才可以
                jump(activity, PersonalInfoActivity.class, bundle);
                break;
            case PublicWebPresenter.NC: //昵称
                bundle.putInt("type", PersonalPresenter.CHANGENICKNAME);
                jump(activity, ChangeInfoActivity.class, bundle);
                break;
            case PublicWebPresenter.GRJJ: //个人简介
                bundle.putInt("type", PersonalPresenter.CHANGEPROFILE);
                jump(activity, ChangeInfoActivity.class, bundle);
                break;
            case PublicWebPresenter.CPFA: //产品方案
                jump(activity, AddProductShowActivity.class, bundle);
                break;
            case PublicWebPresenter.KTKJDL: //开通快捷登录
                jump(activity, OpenLoginActivity.class, bundle);
                break;
            case PublicWebPresenter.ZYXFX: //展业秀分享
                jump(activity, PersonalExhibitionActivity.class, bundle);
                break;
            case PublicWebPresenter.SCFL: //上传费率
                tuUploadfee(activity, bundle);
                break;
            case PublicWebPresenter.BYZP: //保易智评
                CustomerModuleJumpHelper.toJump(activity, "1006", "1006", "", "", "", "");
            case PublicWebPresenter.KHGL: //客户管理
//                jump(activity, ClientManagerActivity.class, bundle);  //需要vip判断
                CustomerModuleJumpHelper.toJump(activity, "1007", "1007", "", "", "", "");
                break;
            case PublicWebPresenter.CPDP: //产品点评
                bundle.putInt(BYContants.BY_EXTRA_PARAMS, BYContants.PRODUCT_TPYE);
             //   jump(activity, BYWebActivity.class, bundle);
                break;
            case PublicWebPresenter.GSDP: //公司点评
                bundle.putInt(BYContants.BY_EXTRA_PARAMS, BYContants.COMPANY_TYPE);
             //   jump(activity, BYWebActivity.class, bundle);
                break;
            case PublicWebPresenter.BXAL: //保险案例
                bundle.putInt(BYContants.BY_EXTRA_PARAMS, BYContants.TRYELIKE_TYPE);
              //  jump(activity, BYWebActivity.class, bundle);
                break;
            case PublicWebPresenter.JHDB: //计划对比
                bundle.putInt(BYContants.BY_EXTRA_PARAMS, BYContants.PLANCONSTART_TYPE);
              //  jump(activity, BYWebActivity.class, bundle);
                break;
        }
    }

    private static void jump(Context context, Class<?> cls, Bundle bundle) {
        Intent intent = new Intent(context, cls);
//        bundle.putString(BBWebHelper.FROM_PAGE, BBWebHelper.PAGE_NAME);
        if (bundle != null) {
            intent.putExtras(bundle);
        }
        context.startActivity(intent);
    }

    /**
     * 上传产品费率
     */
    private static void tuUploadfee(Activity activity, Bundle bundle) {
        String userphone = UserInfor.getInstance().getUserphone();
        if (TextUtils.isEmpty(userphone)) {  //手机号码为空
            showBundleNumberTips(activity);
            return;
        }
        jump(activity, UploadProductfeerateActivity.class, bundle);
    }


    /**
     * 显示提示手机号码为空的dialog
     */
    private static void showBundleNumberTips(final Activity activity) {
        View view = View.inflate(activity, R.layout.dialog_uploadfee_bundlnumber, null);
        DialogUtil.getInstance().creatAlertDialog(activity, view, 266, 171);
        TextView tv_cancel = (TextView) view.findViewById(R.id.text_cancle);
        TextView tv_confirm = (TextView) view.findViewById(R.id.text_confirm);
        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                DialogUtil.getInstance().dismiss();
            }
        });

        tv_confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, BundlePhoneActivity.class);
                activity.startActivity(intent);
                DialogUtil.getInstance().dismiss();
            }
        });
    }


}
